package cn.yotta.user.api.params.login;

import cn.yotta.common.utils.param.AssertUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.util.function.Supplier;

import static cn.yotta.user.api.error.UserCommonErrorCode.PHONE_IS_NULL;

/**
 * @author w_etw
 * @date 2023/4/15 20:33
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
@ToString(callSuper = true)
@ApiModel("手机号密码登录请求参数")
public class LoginByMobilePasswordRequest extends BaseLoginByPasswordRequest {

    @ApiModelProperty(value = "手机号", required = true)
    private String phone;

    @Override
    public Supplier<String> getPrincipal() {
        return this::getPhone;
    }

    @Override
    public void checkValid() {
        super.checkValid();
        AssertUtil.notBlank(this.phone, PHONE_IS_NULL.getCode());
    }
}
